<template>
  <div>
    <div id="echarts_4" style="width: 100%; height: 100%" ref="echartsFour"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "echartsFour",
  data() {
    return {
      sortList: [],
    };
  },
  mounted() {
    this.getDateCarNum();
  },
  methods: {
    echartsFour() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(this.$refs.echartsFour);
      var option = {
        tooltip: {
          trigger: "item",
          formatter: "{b}: <br/>  {c} ({d}%)",
        },

        toolbox: {
          show: false,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            magicType: {
              show: true,
              type: ["pie", "funnel"],
            },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        calculable: true,
        series: [
          {
            name: "排名",
            type: "pie",
            color: ["#33b565", "#20cc98", "#20b9cf", "#2089cf", "#205bcf"],
            radius: [20, 70],
            center: ["70%", "20%"],
            roseType: "area",
            data: [
              { value: this.sortList[0].station_num, name: this.sortList[0].province },
              { value: this.sortList[1].station_num, name: this.sortList[1].province },
              { value: this.sortList[2].station_num, name: this.sortList[2].province },
              { value: this.sortList[3].station_num, name: this.sortList[3].province },
              { value: this.sortList[4].station_num, name: this.sortList[4].province },
              { value: this.sortList[5].station_num, name: this.sortList[5].province },
              { value: this.sortList[6].station_num, name: this.sortList[6].province },
              { value: this.sortList[7].station_num, name: this.sortList[7].province },
              { value: this.sortList[8].station_num, name: this.sortList[8].province },
              { value: this.sortList[9].station_num, name: this.sortList[9].province },
            ],
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      window.addEventListener("resize", function () {
        myChart.resize();
      });
    },

    async getDateCarNum() {
      let result = await this.$API.reqSelectProvinceStationNum();

      result.sort((a, b) => {
        return b.station_num - a.station_num;
      });
      this.sortList = result;
      this.echartsFour();
    },
  },
};
</script>
